using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using Microsoft.Practices.ObjectBuilder;
using LibrErian.Model;

namespace LibrErian.Modules.BasicBook
{
    public partial class ManageItemView : UserControl, IManageGenreView 
    {
        private ManageGenreViewPresenter presenter;

        [CreateNew]
        public ManageGenreViewPresenter Presenter
        {
            set
            {
                presenter = value;
                presenter.View = this;
            }
        }

        public ManageItemView()
        {
            InitializeComponent();
        }

        public void SetGenres(IList items)
        {
            lbItems.DataSource = null;
            lbItems.DataSource = items;
        }

        private void ManageItemView_Load(object sender, EventArgs e)
        {
            presenter.OnViewReady();
        }


        private void btnOk_Click(object sender, EventArgs e)
        {
            presenter.OnOk();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            presenter.OnCancel();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tbItem.Text))
            {
                presenter.AddItem(tbItem.Text);
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lbItems.SelectedIndex >= 0)
            {
                presenter.DeleteItem((Genre)lbItems.SelectedItem);
            }
        }
    }
}
